home *** CD-ROM | disk | FTP | other *** search
- static char sccs_id[] = "%W% %G% %U%";
- /*
- +++
- testwlist
-
- PURPOSE : test wlist class member functions
-
- USAGE : testwlist (no args)
-
- INPUTS :
-
- OUTPUTS : stdout, stderr
-
- DATE : Sun Jan 30 20:37:46 EST 1994
-
- PROJECT : WEH Software
-
- AUTHOR : W. Hatch
-
- COMPANY : Coleman Research Corporation
- 9891 Broken Land Parkway
- Suite 200
- Columbia, Maryland 21045
- Phone (301)621-8600
- FAX (410)7210
-
- ---*/
- /*
- ------------------------------------------------------------------------
- MODIFICATIONS
- DATE PROGRAMMER DESCRIPTION
- ========================================================================
- */
- #include <stdio.h>
- #include <tstring.h>
- #include <wlist.h>
- wlist *wlbuild(wlist *wl, int length);
- int test_FirstData();
- int test_LastData();
- int test_CurrentData();
- int test_NextData();
- int test_PreviousData();
- int test_PrependData();
- int test_PreInsert();
- int test_PostInsert();
- int test_DeleteCurrent();
- int test_Reverse();
- int test_ExchangePrevious();
- int test_ExchangeNext();
- int test_Minimum();
- int test_Maximum();
- int test_Sort();
-
- main(int argc, char **argv)
- {
- if(!test_FirstData())
- {
- printf("wlist::FirstData() failed\n");
- exit(2);
- }
- if(!test_LastData())
- {
- printf("wlist::LastData() failed\n");
- exit(2);
- }
- if(!test_CurrentData())
- {
- printf("wlist::CurrentData() failed\n");
- exit(2);
- }
- if(!test_NextData())
- {
- printf("wlist::NextData() failed\n");
- exit(2);
- }
- if(!test_PreviousData())
- {
- printf("wlist::PreviousData() failed\n");
- exit(2);
- }
- if(!test_PrependData())
- {
- printf("wlist::PrependData() failed\n");
- exit(2);
- }
- if(!test_PreInsert())
- {
- printf("wlist::PreInsert() failed\n");
- exit(2);
- }
- if(!test_PostInsert())
- {
- printf("wlist::PostInsert() failed\n");
- exit(2);
- }
- if(!test_DeleteCurrent())
- {
- printf("wlist::DeleteCurrent() failed\n");
- exit(2);
- }
- if(!test_Reverse())
- {
- printf("wlist::Reverse() failed\n");
- exit(2);
- }
- if(!test_ExchangePrevious())
- {
- printf("wlist::ExchangePrevious() failed\n");
- exit(2);
- }
- if(!test_ExchangeNext())
- {
- printf("wlist::ExchangeNext() failed\n");
- exit(2);
- }
- if(!test_Minimum())
- {
- printf("wlist::Minimum() failed\n");
- exit(2);
- }
- if(!test_Maximum())
- {
- printf("wlist::Maximum() failed\n");
- exit(2);
- }
- if(!test_Sort())
- {
- printf("wlist::Sort() failed\n");
- exit(2);
- }
- printf("\n\twlist passed all tests. the wlist class probably works OK\n");
- printf("\tsend any problem reports or suggestions to uunet!bts!bill\n\n");
- printf("\tGood Luck and may all of your code be correct;\n\n");
- printf("\tBill Hatch Wed Feb 2 13:58:14 EST 1994 \n");
- exit(0);
- }
- /* END main */
- wlist *wlbuild(wlist *wl,int length){
- tstring *ts;
- int i,j;
- char buf[10];
-
-
- for(i=0; i< length; i++)
- {
- ts=new tstring;
- sprintf(buf,"%d",((i+1)%9));
- if(strlen(buf) > 1)
- {
- printf("wlist::wbuild() buffer corrupted %s\n",buf);
- }
- ts->Tstring(buf);
- wl->NextData(ts);
- }
-
- return wl;
- }
- //-------------------------------------------------------------------------
- // test_FirstData
- //-------------------------------------------------------------------------
- int test_FirstData(){
- char *function = "FirstData";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->FirstData("AA");
- if(result==(char *)0 ||!streql(result,"AA"))
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- result = (char *)wl->FirstData();
- if(!streql(result,"AA"))
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- if(wl->Size() != 1)
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- result=(char *)wl->FirstData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 1");
- pass=FALSE;
- }
- result = (char *)wl->FirstData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 1");
- pass=FALSE;
- }
- if(wl->Size() != 1)
- pass=FALSE;
-
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 1");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
-
- result=(char *)wl->FirstData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
- result = (char *)wl->FirstData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
- if(wl->Size() != 2)
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
-
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_LastData
- //-------------------------------------------------------------------------
- int test_LastData(){
- char *function = "LastData";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->LastData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- result = (char *)wl->LastData();
- if(!streql(result,"AA"))
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- if(wl->Size() != 1)
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("empty list ");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- result=(char *)wl->LastData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 1");
- pass=FALSE;
- }
- result = (char *)wl->LastData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 1");
- pass=FALSE;
- }
- if(wl->Size() != 1)
- pass=FALSE;
-
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 1");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
-
- result=(char *)wl->LastData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
- result = (char *)wl->LastData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
- if(wl->Size() != 2)
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
-
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("list size 2");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_CurrentData
- //-------------------------------------------------------------------------
- int test_CurrentData(){
- char *function = "CurrentData";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->CurrentData();
- if(result != (char *)0)
- {
- pass=FALSE;
- PROBLEM("empty list");
- }
- if(wl->Size() != 0)
- {
- pass=FALSE;
- PROBLEM("empty list");
- }
- result=(char *)wl->CurrentData("AA");
- if(!streql(result,"AA"))
- {
- pass=FALSE;
- PROBLEM("empty list after insertion");
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- pass=FALSE;
- PROBLEM("empty list after insertion");
- }
- if(wl->Size() != 1)
- {
- pass=FALSE;
- PROBLEM("empty list after insertion");
- }
- result = (char *)wl->CurrentData("BB");
- if(!streql(result,"BB"))
- {
- pass=FALSE;
- PROBLEM("empty list after insertion");
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- ts=(tstring *)wl->CurrentData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("list size 1");
- }
- result=(char *)wl->CurrentData("AA");
- if(!streql(result,"AA"))
- {
- pass=FALSE;
- PROBLEM("list size 1");
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- pass=FALSE;
- PROBLEM("list size 1");
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- ts=(tstring *)wl->CurrentData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- pass=FALSE;
- PROBLEM("list size 1");
- printf("length %d\n",strlen(result));
- for(int ii=0; ii <= strlen(result); ii++)
- printf("%d ",result[ii]);
- printf("\n");
- printf("result=%s\n\n",result);
- wl->print();
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_NextData()
- //-------------------------------------------------------------------------
- int test_NextData(){
- char *function = "NextData";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->NextData();
- if(result != (char *)0)
- {
- PROBLEM("NextData empty list");
- pass=FALSE;
- }
-
- result=(char *)wl->NextData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData - empty list");
- pass=FALSE;
- }
- if(wl->Size() != 1)
- {
- PROBLEM("NextData - empty list");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData empty list");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- result=(char *)wl->NextData();
- if(result != (char *)0)
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- ts = (tstring *)wl->CurrentData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- result=(char *)wl->NextData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- result=(char *)wl->LastData();
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- ts=(tstring *)wl->FirstData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- ts=(tstring *)wl->CurrentData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- if(wl->Size() != 2)
- {
- PROBLEM("NextData list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- result=(char *)wl->NextData();
- if(result != (char *)0)
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->NextData("AA");
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->LastData();
- if(!streql(result,"AA"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- if(wl->Size() != 3)
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- wl->FirstData();
- ts=(tstring *)wl->NextData();
- result=(char *)ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->FirstData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->NextData("BB");
- if(!streql(result,"BB"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- wl->LastData();
- result=(char *)wl->PreviousData();
- if(!streql(result,"BB"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- wl->LastData();
- result=(char *)wl->NextData();
- if(result != (char *)0)
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->NextData("CCC");
- if(!streql(result,"CCC"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->LastData();
- if(!streql(result,"CCC"))
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- if(wl->Size() != 4)
- {
- PROBLEM("NextData list size 2");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_PreviousData
- //-------------------------------------------------------------------------
- int test_PreviousData(){
- char *function = "PreviousData";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->PreviousData();
- if(result != (char *)0)
- {
- PROBLEM("PreviousData list size 0");
- pass=FALSE;
- }
- result=(char *)wl->PreviousData("AAA");
- if(!streql(result,"AAA"))
- {
- PROBLEM("PreviousData list size 0");
- pass=FALSE;
- }
- if(wl->Size() != 1)
- {
- PROBLEM("PreviousData list size 0");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"AAA"))
- {
- PROBLEM("PreviousData list size 0");
- pass=FALSE;
- }
- result=(char *)wl->FirstData();
- if(!streql(result,"AAA"))
- {
- PROBLEM("PreviousData list size 0");
- pass=FALSE;
- }
- result=(char *)wl->LastData();
- if(!streql(result,"AAA"))
- {
- PROBLEM("PreviousData list size 0");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- ts=(tstring *)wl->PreviousData();
- if(ts != (tstring *)0)
- {
- PROBLEM("PreviousData list size 1");
- pass=FALSE;
- }
- result=(char *)wl->PreviousData("b");
- if(!streql(result,"b"))
- {
- PROBLEM("PreviousData list size 1");
- pass=FALSE;
- }
- if(wl->Size() != 2)
- {
- PROBLEM("PreviousData list size 1");
- pass=FALSE;
- }
- result=(char *)wl->FirstData();
- if(!streql(result,"b"))
- {
- PROBLEM("PreviousData list size 1");
- pass=FALSE;
- }
- ts=(tstring *)wl->LastData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("PreviousData list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- ts=(tstring *)wl->PreviousData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("PreviousData list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->LastData();
- result=(char *)ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("PreviousData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->PreviousData("A");
- if(!streql(result,"A"))
- {
- PROBLEM("PreviousData list size 2");
- pass=FALSE;
- }
- result=(char *)wl->FirstData();
- if(!streql(result,"A"))
- {
- PROBLEM("PreviousData list size 2");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- ts=(tstring *)wl->PreviousData();
- result=(char *)ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("PreviousData list size 3");
- pass=FALSE;
- }
- wl->LastData();
- result=(char *)wl->PreviousData("c");
- if(!streql(result,"c"))
- {
- PROBLEM("PreviousData list size 3");
- pass=FALSE;
- }
- wl->FirstData();
- result=(char *)wl->NextData();
- if(!streql(result,"c"))
- {
- PROBLEM("PreviousData list size 3");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_PrependData
- //-------------------------------------------------------------------------
- int test_PrependData(){
- char *function = "PrependData";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->PrependData("bb");
- if(!streql(result,"bb"))
- {
- PROBLEM("PrependData list size 0");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PrependData list size 0");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- result=(char *)wl->PrependData("bb");
- if(!streql(result,"bb"))
- {
- PROBLEM("PrependData list size 0");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PrependData list size 0");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_PreInsert
- //-------------------------------------------------------------------------
- int test_PreInsert(){
- char *function = "PreInsert";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->PreInsert("bb");
- if(!streql(result,"bb"))
- {
- PROBLEM("PreInsert list size 0");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PreInsert list size 0");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- result=(char *)wl->PreInsert("bb");
- if(!streql(result,"bb"))
- {
- PROBLEM("PreInsert list size 1");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PreInsert list size 1");
- pass=FALSE;
- }
- if(wl->Size() != 2)
- {
- PROBLEM("PreInsert list size 1");
- pass=FALSE;
- }
- result=(char *)wl->FirstData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PreInsert list size 1");
- pass=FALSE;
- }
- ts=(tstring *)wl->LastData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("PreInsert list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- result=(char *)wl->PreInsert("bb");
- if(!streql(result,"bb"))
- {
- PROBLEM("PreInsert list size 3");
- pass=FALSE;
- }
- ts=(tstring *)wl->LastData();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("PreInsert list size 3");
- pass=FALSE;
- }
- result=(char *)wl->PreviousData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PreInsert list size 3");
- pass=FALSE;
- }
- if(wl->Size() != 4)
- {
- PROBLEM("PreInsert list size 3");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_PostInsert
- //-------------------------------------------------------------------------
- int test_PostInsert(){
- char *function = "PostInsert";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- result=(char *)wl->PostInsert("bb");
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 0");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 0");
- pass=FALSE;
- }
- result=(char *)wl->FirstData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 0");
- pass=FALSE;
- }
- result=(char *)wl->LastData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 0");
- pass=FALSE;
- }
- if(wl->Size() != 1)
- {
- PROBLEM("PostInsert list size 0");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- result=(char *)wl->PostInsert("bb");
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 1");
- pass=FALSE;
- }
- result=(char *)wl->CurrentData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 1");
- pass=FALSE;
- }
- ts=(tstring *)wl->FirstData();
- result=(char *)ts->Tstring();
- if(!streql(result,"1"))
- {
- printf("\tresult: %s\n",result);
- PROBLEM("PostInsert list size 1");
- pass=FALSE;
- }
- result=(char *)wl->NextData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 1");
- pass=FALSE;
- }
- result=(char *)wl->NextData();
- if(result != (char *)0)
- {
- PROBLEM("PostInsert list size 1");
- pass=FALSE;
- }
- result=(char *)wl->LastData();
- if(!streql(result,"bb"))
- {
- PROBLEM("PostInsert list size 1");
- pass=FALSE;
- }
- if(wl->Size() != 2)
- {
- PROBLEM("PostInsert list size 0");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_DeleteCurrent
- //-------------------------------------------------------------------------
- int test_DeleteCurrent(){
- char *function = "DeleteCurrent";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- ts=(tstring *)wl->DeleteCurrent();
- if(ts != (tstring *)0)
- {
- PROBLEM("DeleteCurrent list size 0");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- ts=(tstring *)wl->DeleteCurrent();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("DeleteCurrent list size 1");
- pass=FALSE;
- }
- if(wl->Size() != 0)
- {
- PROBLEM("DeleteCurrent list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- ts=(tstring *)wl->DeleteCurrent();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->DeleteCurrent();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- wl->PreviousData();
- ts=(tstring *)wl->DeleteCurrent();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->CurrentData();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
- wl->DeleteAll();
- wlbuild(wl,3);
- ts=(tstring *)wl->DeleteCurrent();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->CurrentData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
-
- wl->DeleteAll();
- wlbuild(wl,3);
- wl->FirstData();
- ts=(tstring *)wl->DeleteCurrent();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->CurrentData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("DeleteCurrent list size 2");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_Reverse
- //-------------------------------------------------------------------------
- int test_Reverse(){
- char *function = "Reverse";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
- wlist *wl2;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
- wl->SetCompareData(compare_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- wl2=wl->Reverse();
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- wl2=wl->Reverse();
- ts=(tstring *)wl2->FirstData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Reverse() list size 1");
- pass=FALSE;
- }
- ts=(tstring *)wl2->NextData();
- if(ts != (tstring *)0)
- {
- PROBLEM("Reverse() list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- wl2->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- wl2=wl->Reverse();
- ts=(tstring *)wl2->FirstData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("Reverse() list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl2->NextData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Reverse() list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl2->NextData();
- if(ts != (tstring *)0)
- {
- PROBLEM("Reverse() list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- wl2->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- wl2=wl->Reverse();
- ts=(tstring *)wl2->FirstData();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("Reverse() list size 3");
- pass=FALSE;
- }
- ts=(tstring *)wl2->NextData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("Reverse() list size 3");
- pass=FALSE;
- }
- ts=(tstring *)wl2->NextData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Reverse() list size 3");
- pass=FALSE;
- }
- ts=(tstring *)wl2->NextData();
- if(ts != (tstring *)0)
- {
- PROBLEM("Reverse() list size 3");
- pass=FALSE;
- }
-
-
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- wl2->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_ExchangePrevious
- //-------------------------------------------------------------------------
- int test_ExchangePrevious(){
- char *function = "ExchangePrevious";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
- wl->SetCompareData(compare_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- ts = (tstring *)wl->ExchangePrevious();
- if(ts != (tstring *)0)
- {
- PROBLEM("ExchangePrevious empty list");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- ts=(tstring *)wl->ExchangePrevious();
- if(ts != (tstring *)0)
- {
- PROBLEM("ExchangePrevious list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- wl->FirstData();
- ts=(tstring *)wl->ExchangePrevious();
- if(ts != (tstring *)0)
- {
- PROBLEM("ExchangePrevious list size 2");
- pass=FALSE;
- }
- wl->LastData();
- ts=(tstring *)wl->ExchangePrevious();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("ExchangePrevious list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->CurrentData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("ExchangePrevious list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->ExchangePrevious();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("ExchangePrevious list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->LastData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("ExchangePrevious list size 2");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- wl->LastData();
- ts=(tstring *)wl->ExchangePrevious();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("ExchangePrevious list size 3");
- pass=FALSE;
- }
- wl->PreviousData();
- ts=(tstring *)wl->ExchangePrevious();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("ExchangePrevious list size 3");
- pass=FALSE;
- }
- ts=(tstring *)wl->FirstData();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("ExchangePrevious list size 3");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_ExchangeNext
- //-------------------------------------------------------------------------
- int test_ExchangeNext(){
- char *function = "ExchangeNext";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
- wl->SetCompareData(compare_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- ts = (tstring *)wl->ExchangeNext();
- if(ts != (tstring *)0)
- {
- PROBLEM("ExchangeNext empty list");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- ts=(tstring *)wl->ExchangeNext();
- if(ts != (tstring *)0)
- {
- PROBLEM("ExchangeNext list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- wl->LastData();
- ts=(tstring *)wl->ExchangeNext();
- if(ts != (tstring *)0)
- {
- PROBLEM("ExchangeNext list size 2");
- pass=FALSE;
- }
- wl->FirstData();
- ts=(tstring *)wl->ExchangeNext();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("ExchangeNext list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->CurrentData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("ExchangeNext list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->ExchangeNext();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("ExchangeNext list size 2");
- pass=FALSE;
- }
- ts=(tstring *)wl->LastData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("ExchangeNext list size 2");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- wl->FirstData();
- ts=(tstring *)wl->ExchangeNext();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("ExchangeNext list size 3");
- pass=FALSE;
- }
- wl->NextData();
- ts=(tstring *)wl->ExchangeNext();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("ExchangeNext list size 3");
- wl->print();
- pass=FALSE;
- }
- ts=(tstring *)wl->LastData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("ExchangeNext list size 3");
- wl->print();
- pass=FALSE;
- }
- ts = (tstring *)wl->ExchangeNext();
- if(ts != (tstring *)0)
- {
- PROBLEM("ExchangeNext list size 3");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_Minimum
- //-------------------------------------------------------------------------
- int test_Minimum(){
- char *function = "Minimum";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
- wl->SetCompareData(compare_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- ts=(tstring *)wl->Minimum();
- if(ts != (tstring *)0)
- {
- pass=FALSE;
- PROBLEM("Minimum list size 0");
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- ts=(tstring *)wl->Minimum();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- printf("result %s\n",result);
- PROBLEM("Minimum list size 1");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 1");
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- ts=(tstring *)wl->Minimum();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 2");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 2");
- }
- wl->Reverse();
- ts=(tstring *)wl->Minimum();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 2");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 2");
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- ts=(tstring *)wl->Minimum();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 3");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 3");
- }
- wl->Reverse();
- ts=(tstring *)wl->Minimum();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 3");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Minimum list size 3");
- }
-
-
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_Maximum
- //-------------------------------------------------------------------------
- int test_Maximum(){
- char *function = "Maximum";
- tstring *ts;
- wlist *wl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
- wl->SetCompareData(compare_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- ts=(tstring *)wl->Maximum();
- if(ts != (tstring *)0)
- {
- pass=FALSE;
- PROBLEM("Maximum list size 0");
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- ts=(tstring *)wl->Maximum();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 1");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"1"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 1");
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- ts=(tstring *)wl->Maximum();
- result = ts->Tstring();
- if(!streql(result,"2"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 2");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"2"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 2");
- }
- wl->Reverse();
- ts=(tstring *)wl->Maximum();
- result = ts->Tstring();
- if(!streql(result,"2"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 2");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"2"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 2");
- }
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- ts=(tstring *)wl->Maximum();
- result = ts->Tstring();
- if(!streql(result,"3"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 3");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"3"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 3");
- }
- wl->Reverse();
- ts=(tstring *)wl->Maximum();
- result = ts->Tstring();
- if(!streql(result,"3"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 3");
- }
- ts=(tstring *)wl->CurrentData();
- result = ts->Tstring();
- if(!streql(result,"3"))
- {
- pass=FALSE;
- PROBLEM("Maximum list size 3");
- }
-
-
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- return passall;
- }
- //-------------------------------------------------------------------------
- // test_Sort
- //-------------------------------------------------------------------------
- int test_Sort(){
- char *function = "Sort";
- tstring *ts;
- wlist *wl;
- wlist *xl;
- int pass=TRUE;
- int passall=TRUE;
- char *result;
-
- wl=new wlist;
- wl->SetPrintData(print_tstring);
- wl->SetCompareData(compare_tstring);
-
- //-----------------------------------------------------------------
- // test with empty list
- //-----------------------------------------------------------------
- xl=wl->Sort();
- if(xl == (wlist *)0 || xl->Size() != 0)
- {
- PROBLEM("Sort() list size 0");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed empty list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- delete xl;
- //-----------------------------------------------------------------
- // test with one nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,1);
- xl=wl->Sort();
- if(xl == (wlist *)0 || xl->Size() == 0)
- {
- PROBLEM("Sort() list size 0");
- pass=FALSE;
- }
- ts=(tstring *)xl->FirstData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Sort() list size 1");
- pass=FALSE;
- }
- if(!pass)
- {
- printf("\tfunction %s failed 1 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- delete xl;
- //-----------------------------------------------------------------
- // test with 2 nodes in list list
- //-----------------------------------------------------------------
- wlbuild(wl,2);
- xl=wl->Sort();
- ts=(tstring *)xl->FirstData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Sort() list size 2");
- pass=FALSE;
- }
- ts=(tstring *)xl->NextData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("Sort() list size 2");
- pass=FALSE;
- }
- delete xl;
- wl->Reverse();
- xl=wl->Sort();
- ts=(tstring *)xl->FirstData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Sort() list size 2");
- pass=FALSE;
- }
- ts=(tstring *)xl->NextData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("Sort() list size 2");
- pass=FALSE;
- }
-
- if(!pass)
- {
- printf("\tfunction %s failed 2 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- wl->DeleteAll();
- delete xl;
- //-----------------------------------------------------------------
- // test with 3 nodes in list
- //-----------------------------------------------------------------
- wlbuild(wl,3);
- xl=wl->Sort();
- ts=(tstring *)xl->FirstData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Sort() list size 3");
- pass=FALSE;
- }
- ts=(tstring *)xl->NextData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("Sort() list size 3");
- pass=FALSE;
- }
- ts=(tstring *)xl->NextData();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("Sort() list size 3");
- pass=FALSE;
- }
- delete xl;
- wl->Reverse();
- xl=wl->Sort();
- ts=(tstring *)xl->FirstData();
- result=ts->Tstring();
- if(!streql(result,"1"))
- {
- PROBLEM("Sort() list size 3");
- pass=FALSE;
- }
- ts=(tstring *)xl->NextData();
- result=ts->Tstring();
- if(!streql(result,"2"))
- {
- PROBLEM("Sort() list size 3");
- pass=FALSE;
- }
- ts=(tstring *)xl->NextData();
- result=ts->Tstring();
- if(!streql(result,"3"))
- {
- PROBLEM("Sort() list size 3");
- pass=FALSE;
- }
- delete xl;
-
- if(!pass)
- {
- printf("\tfunction %s failed 3 element list test\n",function);
- passall=FALSE;
- pass=TRUE;
- }
- delete wl;
- return passall;
- }
-